﻿using System.Collections.Generic;
using System.Diagnostics.Contracts;

namespace System.Reactive.Concurrency
{
	[ContractClass(typeof(ScheduledItemContract<>))]
	public abstract class ScheduledItem<TAbsolute> : IScheduledItem<TAbsolute>, IComparable<ScheduledItem<TAbsolute>>
		where TAbsolute : IComparable<TAbsolute>
	{
		public TAbsolute DueTime
		{
			get
			{
				return default(TAbsolute);
			}
		}

		public ScheduledItem(TAbsolute dueTime, IComparer<TAbsolute> comparer)
		{
			Contract.Requires(comparer != null, null, "comparer != null");
		}

		protected abstract IDisposable InvokeCore();

		public void Invoke()
		{
		}

		public int CompareTo(ScheduledItem<TAbsolute> other)
		{
			return 0;
		}
	}

	[ContractClassFor(typeof(ScheduledItem<>))]
	internal abstract class ScheduledItemContract<TAbsolute> : ScheduledItem<TAbsolute>
		where TAbsolute : IComparable<TAbsolute>
	{
		public ScheduledItemContract()
			: base(default(TAbsolute), null)
		{
		}

		protected override IDisposable InvokeCore()
		{
			Contract.Ensures(Contract.Result<IDisposable>() != null, null, "Contract.Result<IDisposable>() != null");
			return null;
		}
	}
}